package com.bl.student.api.controller;

import com.bl.student.common.ApiResponseBody;
import com.bl.student.dao.model.UserRecordEntity;
import com.bl.student.dao.model.UserShareEntity;
import com.bl.student.service.biz.main.MainService;
import com.bl.student.service.biz.record.RecordService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.DelListBody;
import com.bl.student.service.vo.record.*;
import com.bl.student.service.vo.user.UserInfoModifyVo;
import com.santoker.roastassistant.share.SharedData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * Created by liangweikang on 20/6/27.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/painters/apis"})
@Api(value = "记录相关", description = "记录相关")
public class RecordController extends BaseController {

    @Autowired
    MainService mainService;

    @Autowired
    RecordService recordService;

    @ApiOperation(value = "单个用户记录列表", notes = "单个用户记录列表 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<List<UserRecordEntity>> goodsList(
            @RequestParam(value = "userId", required = true) int userId,
            HttpServletRequest request) {

        List<UserRecordEntity> userRecordEntities = recordService.getUserRecordEntityList(userId);

        return ApiResponseBody.createSuccessBody(userRecordEntities);
    }

    @ApiOperation(value = "单个用户分享列表", notes = "单个用户分享列表 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_share_list"})
    public ApiResponseBody<List<UserRecordEntity>> shareList(
            @RequestParam(value = "userId", required = true) int userId,
            HttpServletRequest request) {

        List<UserRecordEntity> userShareEntityList = recordService.getShareList(userId);

        return ApiResponseBody.createSuccessBody(userShareEntityList);
    }

    @ApiOperation(value = "单个分享记录", notes = "单个分享记录 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recordId", value = "recordId", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_record"})
    public ApiResponseBody<SharedData> share(
            @RequestParam(value = "recordId", required = true) String recordId,
            HttpServletRequest request) {

        SharedData sharedData = recordService.getSharedData(recordId);

        return ApiResponseBody.createSuccessBody(sharedData);
    }

    @ApiOperation(value = "精选用户列表", notes = "精选用户列表 ")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_user_list_select"})
    public ApiResponseBody<List<UserVo>> userListSelect(
            HttpServletRequest request) {

        List<UserVo> userVoList = recordService.getUserNameListSelect();

        return ApiResponseBody.createSuccessBody(userVoList);
    }

    @ApiOperation(value = "用户列表", notes = "用户列表")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_all_user_list"})
    public ApiResponseBody<List<UserVo>> getAllUser(
            HttpServletRequest request) {

        List<UserVo> userVoList = recordService.getAllUser();

        return ApiResponseBody.createSuccessBody(userVoList);
    }

    @ApiOperation(value = "姓名搜索用户", notes = "姓名搜索用户 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "userName", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/search_user_by_name"})
    public ApiResponseBody<List<UserVo>> searchUserByName(
            @RequestParam(value = "userName", required = true) String userName,
            HttpServletRequest request) {

        List<UserVo> UserVoList = recordService.searchUserByName(userName);

        return ApiResponseBody.createSuccessBody(UserVoList);
    }

    @ApiOperation(value = "手机号搜索用户", notes = "手机号搜索用户 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "mobile", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/search_user_by_mobile"})
    public ApiResponseBody<List<UserVo>> searchUserByMobile(
            @RequestParam(value = "mobile", required = true) String mobile,

            HttpServletRequest request) {

        List<UserVo> UserVoList = recordService.searchUserByMobile(mobile);

        return ApiResponseBody.createSuccessBody(UserVoList);
    }

    @ApiOperation(value = "搜索曲线", notes = "搜索曲线 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "title", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "searchType", value = "searchType", required = false, paramType = "query", dataType = "int")})
    @GetMapping(value = {"/search_record"})
    public ApiResponseBody<List<UserRecordEntity>> searchRecord(
            @RequestParam(value = "title", required = false) String title,
            @RequestParam(value = "searchType", required = false) int searchType,
            HttpServletRequest request) {

        List<UserRecordEntity> userRecordEntities = recordService.getUserRecordEntityListByTitle(title, searchType);

        return ApiResponseBody.createSuccessBody(userRecordEntities);
    }

    @ApiOperation(value = "所有曲线", notes = "所有曲线 ")
    @ApiImplicitParams({})
    @GetMapping(value = {"/all_record"})
    public ApiResponseBody<List<UserRecordEntity>> recordAll(
            HttpServletRequest request) {

        List<UserRecordEntity> userRecordEntities = recordService.getAllRecord();

        return ApiResponseBody.createSuccessBody(userRecordEntities);
    }

    @ApiOperation(value = "所有训练集曲线", notes = "所有训练集曲线 ")
    @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "type", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/all_train_record"})
    public ApiResponseBody<List<UserRecordTrainVo>> recordAllTrain(
            @RequestParam(value = "type", required = true) String type,
            HttpServletRequest request) {

        List<UserRecordTrainVo> userRecordTrainVoList = recordService.getAllTrainRecord(type);

        return ApiResponseBody.createSuccessBody(userRecordTrainVoList);
    }

    @ApiOperation(value = "用户分享列表", notes = "用户分享列表")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_user_list"})
    public ApiResponseBody<List<UserVo>> userList(
            HttpServletRequest request) {

        List<UserVo> userVoList = recordService.getUserNameList();

        return ApiResponseBody.createSuccessBody(userVoList);
    }

    @ApiOperation(value = "增加记录信息", notes = "修改记录信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add_record"})
    public ApiResponseBody add(
            @Valid @RequestBody RecordAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.add(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "更新用户曲线的title与type", notes = "更新用户曲线的title与type ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/update_user_record"})
    public ApiResponseBody updateUserRecord(
            @Valid @RequestBody RecordModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.updateUserRcord(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "编辑用户信息", notes = "编辑用户信息")
    @ApiImplicitParams({})
    @PostMapping(value = {"/update_user_info"})
    public ApiResponseBody updateUserInfo(
            @Valid @RequestBody UserInfoModifyVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.updateUserInfo(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "设置是否为精选曲线", notes = "设置是否为精选")
    @ApiImplicitParams({})
    @PostMapping(value = {"/set_is_selected"})
    public ApiResponseBody setIsSelect(
            @Valid @RequestBody ShareAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.setIsSelect(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "设置是否为训练集", notes = "设置是否为训练集")
    @ApiImplicitParams({})
    @PostMapping(value = {"/set_is_train"})
    public ApiResponseBody setIsTrain(
            @Valid @RequestBody RecordTrainVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.setIsTrain(body);

        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "删除批量训练集", notes = "删除批量训练集 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_train_list"})
    public ApiResponseBody delTrainList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        recordService.delTrainList(body);

        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "增加分享信息", notes = "修改记录信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add_share"})
    public ApiResponseBody addShare(
            @Valid @RequestBody ShareAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.addShare(body);

        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "增加记录信息", notes = "修改记录信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/del_record"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.del(body);

        return ApiResponseBody.createSuccessBody("success");
    }

    @ApiOperation(value = "增加记录信息", notes = "修改记录信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/del_all"})
    public ApiResponseBody delAll(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.delAll(body);

        return ApiResponseBody.createSuccessBody("success");
    }

    @ApiOperation(value = "增加记录信息", notes = "修改记录信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/del_share"})
    public ApiResponseBody delShare(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        recordService.delShare(body);

        return ApiResponseBody.createSuccessBody(null);
    }



    @ApiOperation(value = "版本信息", notes = "版本信息 ")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_version"})
    public ApiResponseBody<String> getVersion(
            HttpServletRequest request) {

        return ApiResponseBody.createSuccessBody("9.27.0 | 11.15.0  | 12.30.0");
    }
}
